const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    time:"2019-11-12",
    people:"125",

    receivable:"5",
    receipts:"5",
    UnitPrice:"2.00",
    FullAmount:"10.00",
    activeName: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
    activeNames2: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],
    list:[],
    audit:false
  },
  onChange(event) {
    console.log(event.detail)
    this.setData({
      activeName: event.detail
    });
  },
  changeCollapse2(event) {
    this.setData({
      activeNames2: event.detail
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
    const record = JSON.parse(options.data)
    const { stockOrderId = 0, smallCanteenPurchaseId = 0, collarId=0, audit=false,type } = record
    this.setData({ stockOrderId, smallCanteenPurchaseId, collarId, audit, type })

    if (type===0){
      wx.setNavigationBarTitle({
        title: '新食堂食材进货清单',
      })
      app.reqFetch.getOrderDetails({ stockOrderId }, (res) => {
        const { stockorder, list } = res
        this.setData({ stockorder, list })
      })
    } else if (type === 1){
      wx.setNavigationBarTitle({
        title: '新食堂主食领取清单',
      })
      app.reqFetch.collarmxdetails({ collarId }, (res) => {
        const { collarMx } = res
        const list = [{ gys: '主食领取列表', mxlist: collarMx }]
        this.setData({ list })
      })
    } if (type === 2) {
      wx.setNavigationBarTitle({
        title: '小食堂申请清单',
      })
      app.reqFetch.smallcanteenpurchasemxdetails({ smallCanteenPurchaseId }, (res) => {
        const canteensList = JSON.parse(res.smallCanteenPurchase.boxId)
        console.log(canteensList.list)
        this.setData({
          canteensList: canteensList.list
        })
        const list = res.list
        this.setData({ list })
      })
    }




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

  clickImg: function (e) {

    const { entityPhoto } = e.currentTarget.dataset.record

    wx.previewImage({
      urls: [entityPhoto], //需要预览的图片http链接列表，注意是数组
      current: '', // 当前显示图片的http链接，默认是第一个
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  handleConfirm(){
    const { stockOrderId, type, smallCanteenPurchaseId, collarId} = this.data
    if(type===0){
      app.reqFetch.pageAdminUpdate({ stockOrderId, status: 4 }, (res) => {
        wx.showToast({
          title: '清单确认到货',
          icon: 'none'
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '/pages/chef-home/chef-home',
          })
        }, 700)
      })

    } else if (type === 2){
      app.reqFetch.smallcanteenpurchasepageAdminUpdate({ smallCanteenPurchaseId, status: 4 }, (res) => {
        wx.showToast({
          title: '清单确认到货',
          icon: 'none'
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '/pages/chef-home/chef-home',
          })
        }, 700)
      })
    } else if (type === 1) {
      app.reqFetch.collarpageAdminUpdate({ collarId, status: 4 }, (res) => {
        wx.showToast({
          title: '清单确认到货',
          icon: 'none'
        })
        setTimeout(function () {
          wx.navigateTo({
            url: '/pages/chef-home/chef-home',
          })
        }, 700)
      })
    }


  },

})